<?php $this->_extends('_layouts/main_layout'); ?>
<?php $this->_block('title'); ?>
<?php echo "Campaigns"; ?>
<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>
<div id="content" class="box">
	<h1>Campaigns</h1>
	<div id="menu" class="box">
		<ul class="box">
			<li><a href="<?php echo url('campaign/add');?>"><span>Add</span></a></li>
		</ul>
	</div>
	<div id="search" class="search">
		<form method="post" action="<?php echo url('campaign/show'); ?>">
		<input type="text" name="name" value="<?php echo isset($name) ? $name : ''; ?>" /><input type="submit" value="Search" />
		<div id="filter" class="filter">
			
				<label>Publisher</label>
				<?php
					 echo Util::buildDropDownList(
					 	array('id'=>'publisher', 'name'=>'publisher'),
					 	$publishers,
					 	isset($publisher) ? $publisher: false,
					 	array('k'=>'', 'l'=>'--All--')
					 );
				?>
				<label>Sub</label>
				<?php
					 echo Util::buildDropDownList(
					 	array('id'=>'sub', 'name'=>'sub'),
					 	$subs,
					 	isset($sub) ? $sub: false,
					 	array('k'=>'', 'l'=>'--All--')
					 );
				?>
				<label>Offer</label>
				<?php
					 echo Util::buildDropDownList(
					 	array('id'=>'offer', 'name'=>'offer'),
					 	$offers,
					 	isset($offer) ? $offer: false,
					 	array('k'=>'', 'l'=>'--All--')
					 );
				?>
			
		</div>
		</form>
	</div>
		<?php if (isset($infos)) 
				{
					foreach ($infos as $info)
					{
		?>
				<p class="msg info"><?php echo $info;?></p>
		<?php		}
				}
		?>
	<table class="full-size">
		<tbody>
			<tr>
				<th>Name</th>
				<th>Publisher</th>
				<th>Sub</th>
				<th>Offer</th>
				<th>Tag Code</th>
				
			</tr>
			<?php
				if(!empty($campaigns)){
					$bg = false;
					foreach ($campaigns as $cam)
					{
			?>
						<tr <?php if ($bg) echo 'class="bg"';?>>
							<td><?php echo $cam['campaign_name'];?></td>
							<td><?php echo $cam['publisher_name'];?></td>
							<td><?php echo $cam['sub_name'];?></td>
							<td><?php echo $cam['offer_name'];?></td>
							<td>
								<a href="#" onclick="showTagCode(<?php echo $cam['campaign_id'];?>)">Show</a>
								<div id="pixel_<?php echo $cam['campaign_id']; ?>" style="display:none" title="<?php echo 'Tag code -- ' .$cam['campaign_name'] ;?>">
									<textarea readonly="readonly" id="code_<?php echo $cam['campaign_id']; ?>"><?php echo $cam['pixel'];?></textarea>
									<!--  <input id="test" type="button" value="Copy to clipboard" class="ui-state-default ui-corner-all"
										 onclick="copyTagCode(<?php echo $cam['campaign_id']; ?>)"/>-->
								</div>
							</td>				
						</tr>
			<?php
						$bg = !$bg;
					}
				}
			?>
		</tbody>
	</table>
</div>
<script type="text/javascript">
	function showTagCode(node){
		var nodeId = '#pixel_' + node;
		$(nodeId).dialog();
		return false;
	}

	function copyTagCode(node){
		var codeId = '#code_' + node;
		$(codeId).parent().dialog('close');
	}
</script>
<?php $this->_endblock(); ?>
